import { IGenerator } from 'vs/kendryte/vs/workbench/fpioaConfig/node/generateorContribution';
import { IChipGeneratorConfig } from 'vs/kendryte/vs/workbench/fpioaConfig/common/packagingTypes';
import { IFuncIOMap } from 'vs/kendryte/vs/workbench/fpioaConfig/common/types';

export class SourceGenerator implements IGenerator {
	filename = 'fpioa-config.c';

	public generate(config: IChipGeneratorConfig, funcPinMap: IFuncIOMap): string {
		const generatedConfigSections: string[] = [];

		funcPinMap.forEach((io, pinFuncID) => {
			generatedConfigSections.push(`ret += ${config.setterFuncName}(${io}, ${config.funcNamePrefix}${pinFuncID})`);
		});

		return `/**
 * This File Is Generated By maix-ide, do not modify directly.
 * 
 */
#include "${config.libraryName}.h"
#include "fpioa-config.h"

int configure_fpioa() {
	int ret = 0;
	${generatedConfigSections.map(line => line + ';\n\t').join('')}
	return ret;
}
`;
	}
}

export class HeaderGenerator implements IGenerator {
	filename = 'fpioa-config.h';

	public generate(): string {
		return `/**
 * This File Is Generated By maix-ide, do not modify directly.
 * 
 */
#ifndef _MAIX_FPIOA_CONFIG_H
#define _MAIX_FPIOA_CONFIG_H

#define GUI_FPIOA_CONFIGURE \
	gui_configure_fpioa();

int configure_fpioa();

#endif /* _MAIX_FPIOA_CONFIG_H */
`;
	}
}

